// index.js
// index.js
const audioCtx = wx.createWebAudioContext()
Page({
  data: {
    translateX: 0,
    cdList:[
      {"cdName":"五角大楼","money":"20/h"},
      {"cdName":"白宫","money":"50/h"},
      {"cdName":"华盛顿","money":"100/h"},
    ],
    myData:[],
    system_value:''
  },
   onReady: function() {
     wx.request({
       url: 'http://192.168.0.143/site/getSiteInfo',
       success:(data)=>{
         this.setData({
          myData:data.data.data
         });
       },
     })
     
  },
  // onShow: function(){
  //   wx.request({
  //     url: 'http://192.168.0.14/config/getValue?system_key=home_title',
  //     success:(data)=>{
  //       console.log('我的'+data);
  //       this.setData({
  //         system_value:data.data.data[0].system_value
  //       });
  //     },
  //   })
  // },
  onLoad: function () {
    wx.startDeviceMotionListening({
      interval: 'game'
    });

    wx.onDeviceMotionChange((res) => {
      console.log('Device Motion:', res); // 添加调试日志
      const gamma = res.gamma; // 获取设备左右倾斜的角度
      const translateX = gamma * 5; // 这里简单地将gamma乘以一个系数作为水平移动距离

      this.setData({
        translateX: translateX
      });
    });
  },

  onUnload: function () {
    // 页面卸载时停止监听设备运动变化
    wx.stopDeviceMotionListening();
  },
  jumpTo(){
    wx.navigateTo({
      url:"/secondaryPage/venueDetail/venueDetail",
    })
  },

  

loadAudio (url){
  return new Promise((resolve) => {
    wx.request({
      url,
      responseType: 'arraybuffer',
      success: res => {
        console.log('res.data', res.data)
        audioCtx.decodeAudioData(res.data, buffer => {
          resolve(buffer)
        }, err => {
          console.error('decodeAudioData fail', err)
          reject()
        })
      },
      fail: res => {
        console.error('request fail', res)
        reject()
      }
    })
  })
},
      // onReady(){
      //   this.loadAudio('https://ws6.stream.qqmusic.qq.com/O400000ZqX904LgibD.ogg?guid=2973197690&vkey=7BF5BE63985D90636CE76786C72F8933A6CEA929498BA0E835268DAD5145D91CF2FE52494B0533A8E4FC2E6EF2DB9697CD6014630AA9F0EF__v2b9ab84d&uin=3524059673&fromtag=120532').then(buffer => {
      //     let source = audioCtx.createBufferSource()
      //     source.buffer = buffer
      //     source.connect(audioCtx.destination)
      //     source.start()
      //   }).catch(() => {
      //     console.log('fail')
      //   })
      // }
});
